﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SeCompUFSCarWeb.Administration
{
    public partial class GerarCertificados : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Confirmar_Click(object sender, EventArgs e)
        {
            string strconn = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            MySqlConnection conn = new MySqlConnection(strconn);

            string query = "SELECT DISTINCT presenca.EVE_ID, presenca.INS_ID,  aspnetusers.FullName FROM secomp.aspnetusers LEFT JOIN secomp.signup ON secomp.aspnetusers.id = secomp.signup.user_id LEFT JOIN secomp.presenca ON secomp.presenca.INS_ID = secomp.signup.id WHERE  INS_ID = signup.id and eve_id = " + DropBoxEvento.SelectedValue;


            MySqlCommand cmd = new MySqlCommand(query, conn);

            try
            {
                conn.Open();
                MySqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    PDF.PDF.GerarPDF(Server.MapPath("~/PDF/Certificados/" + reader.GetInt32("EVE_ID").ToString() + "//").ToString(), Server.MapPath("~/PDF/Modelos/" + reader.GetInt32("EVE_ID").ToString() + ".jpg").ToString(), reader.GetString("FullName").ToUpper(), reader.GetUInt32("INS_ID").ToString());
                }
            }
            catch (Exception)
            {
                
                throw;
            }


        }
    }
}